package com.parfinex.sims.servlet;

import com.parfinex.sims.dao.ClassDao;
import com.parfinex.sims.entity.ClassInfo;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Description:
 *
 * @date 2021-11-15 23:14
 * @author lijh
 * @version 1.0
 */
@WebServlet(name = "OperateClassServlet", value = "/OperateClassServlet")
public class OperateClassServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*设置获取到的元素的字符编码为UTF8*/
        request.setCharacterEncoding("UTF-8");
        /*把createclass.jsp中form表单填写的数据，传递到实体类中*/
        ClassInfo classInfo = new ClassInfo();
        classInfo.setClassName(request.getParameter("className")) ;
        classInfo.setGradeName(request.getParameter("gradeName"));
        classInfo.setMasterTeacher(request.getParameter("masterTeacher"));
        classInfo.setClassSlogan(request.getParameter("classSlogan"));
        classInfo.setClassNumberCount(Integer.parseInt(request.getParameter("classNumber")));
        System.out.println(Integer.parseInt(request.getParameter("classNumber")));
        /*执行数据库的插入操作*/
        ClassDao classDao = new ClassDao();
        try {
            //把获取到的classInfo对象传到sql语句中的参数
            classDao.updateClass(classInfo);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        response.sendRedirect("classmanagement.jsp");
    }
}
